package com.company.Io;

import com.company.AppConfig;
import com.company.TranslationText;
import com.company.Utils.regUtils;

import java.io.*;

public class ReadText {
    public static void readText(String name){
        try {
            ReadText.writeLineText(AppConfig.inText,"<resources>");
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(name))));
            String text = "";
            text = reader.readLine();
            while ((text = reader.readLine()) != null){
                Thread.sleep(3000);
                System.out.print(text);
                String[] texts = regUtils.getData(text);
                if(texts[1] != null){
                    TranslationText.translationContent(texts,"zh-CN","mn");
                }
            }
            ReadText.writeLineText(AppConfig.inText,"</resources>");
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void writeLineText(String fielname,String text){
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(fielname),true)));
            writer.write(text+"\r\n");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
